package com.bigdata.spark.core.test

import java.io.{ObjectOutputStream, OutputStream}
import java.net.Socket

object Driver {
  def main(args: Array[String]): Unit = {
    //连接服务器
    val client1 = new Socket("localhost", 9999)
    val client2 = new Socket("localhost", 8888)

    val task = new Task()

    val out1:OutputStream = client1.getOutputStream
    //创建发送对象
    val objOut1 = new ObjectOutputStream(out1)

    val subTask = new SubTask()
    subTask.logic = task.logic
    // 取List中的2个元素
    subTask.datas = task.datas.take(2)
    //发送对象
    objOut1.writeObject(subTask)

    out1.flush()
    out1.close()
    client1.close()


    val out2:OutputStream = client2.getOutputStream
    val objOut2 = new ObjectOutputStream(out2)

    val subTask2 = new SubTask()
    subTask2.logic = task.logic
    // 取List中的2个元素
    subTask2.datas = task.datas.takeRight(2)
    //发送对象
    objOut2.writeObject(subTask2)

    out2.flush()
    out2.close()
    client2.close()
    println("客户端数据发送完毕！！")
  }
}
